/* main.c */

#include "app_inc.h"
#include "fsl_edma.h"
#include "fsl_uart.h"


#include <stdint.h>


int main(void)
{
    
    /* Initialize the board. */
    BSP_InitSystem();
    BSP_InitStdioUART(115200);
    
    uint8_t SrcBuf[] = "UART send with DMA\r\n";

    /* enable UART DMA trigger */
    UART0->C2 |= UART_C2_TIE_MASK;
    UART0->C5 |= UART_C5_TDMAS_MASK;

    /* enable DMA and DMAMUX clock */
    SIM->SCGC6 |= SIM_SCGC6_DMAMUX_MASK;
    SIM->SCGC7 |= SIM_SCGC7_DMA_MASK;

    /* configure DMAMUX */
    DMAMUX->CHCFG[0]= DMAMUX_CHCFG_ENBL_MASK| DMAMUX_CHCFG_SOURCE(3);

    /* source configuration */
    DMA0->TCD[0].SADDR = (uint32_t)SrcBuf;
    DMA0->TCD[0].ATTR = DMA_ATTR_SSIZE(0);
    DMA0->TCD[0].SOFF= 1;
    DMA0->TCD[0].SLAST = 0;
    
    /* destination configuration */
    DMA0->TCD[0].DADDR = (uint32_t)&UART0->D;
    DMA0->TCD[0].ATTR = DMA_ATTR_DSIZE(0);
    DMA0->TCD[0].DOFF= 0;
    DMA0->TCD[0].DLAST_SGA= 0;
    
    /* set CITER and BITER to maximum value */
    DMA0->TCD[0].CITER_ELINKNO = sizeof(SrcBuf);
    DMA0->TCD[0].BITER_ELINKNO = sizeof(SrcBuf);
    DMA0->TCD[0].NBYTES_MLNO = 1;
    
    /* enable auto disable request */
    DMA0->TCD[0].CSR |= DMA_CSR_DREQ_MASK; 
    
    /* start transfer */
    DMA0->SERQ = DMA_SERQ_SERQ(0);



    while (1)
    {

    }
}

